package com.jiesen.base.modules.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jiesen.base.modules.login.jsLoginUser.model.JsLoginUser;
import org.springframework.stereotype.Service;

import com.jiesen.base.baseDao.BaseServiceImpl;
import com.jiesen.base.modules.company.mapper.JsPublicUsersRecordMapper;
import com.jiesen.base.modules.company.model.JsPublicUsersRecord;
import com.jiesen.base.modules.company.service.IJsPublicUsersRecordService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 公海认领记录表 服务实现类
 * </p>
 *
 * @author bao
 */
@Service
public class JsPublicUsersRecordServiceImpl extends BaseServiceImpl<JsPublicUsersRecordMapper, JsPublicUsersRecord>implements IJsPublicUsersRecordService {

    @Override
    public  List<JsPublicUsersRecord> selectByUserIdAndPublicId(Integer id, Integer pid) {
        QueryWrapper<JsPublicUsersRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("public_users_id",pid);
        queryWrapper.eq("user_id",id);
        List<JsPublicUsersRecord> jsPublicUsersRecords = baseMapper.selectList(queryWrapper);
        return jsPublicUsersRecords;
    }

    @Override
    @Transactional(readOnly=false)
    public int updateUserRecord(Integer uid,Integer pid,JsPublicUsersRecord jsPublicUsersRecord) {
        UpdateWrapper<JsPublicUsersRecord> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_id",uid);
        updateWrapper.eq("public_users_id", pid);
        return baseMapper.update(jsPublicUsersRecord, updateWrapper);
    }

    @Override
    public int findCountPublicUser(Integer uid) {
        QueryWrapper<JsPublicUsersRecord> queryWrapper = new QueryWrapper();
        queryWrapper.select("count(*) as count ").eq("user_id", uid);
        queryWrapper.ne("state",0);
        List<JsPublicUsersRecord> list = baseMapper.selectList(queryWrapper);
        return list.get(0).getCount();
    }
}
